<script lang="jsx" setup>
import { ref } from 'vue';
import useResetTableRef from '@/hooks/common/resetTableRef';

const [searchParams, resetSearchParams] = useResetTableRef({
  moduleNo: null,
  custProdNo: null,
  custAb: null
});

const formList = [
  {
    type: 'input',
    key: 'moduleNo',
    label: '生产型号',
    span: 6,
    placeholder: '请输入生产型号'
  },
  {
    type: 'input',
    key: 'custProdNo',
    label: '客户型号',
    span: 6,
    placeholder: '请输入客户型号'
  },
  {
    type: 'input',
    key: 'custAb',
    label: '客户名称',
    span: 6,
    placeholder: '请输入客户名称'
  }
];

const tableRef = ref(null);

const column = [
  {
    key: 'dataIndex',
    dataIndex: 'dataIndex',
    title: '序号',
    width: 70,
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'moduleNo',
    dataIndex: 'moduleNo',
    title: '生产型号',
    align: 'center',
    checked: true,
    ellipsis: true,
    width: 160,
    customRender: ({ record }) => {
      return <span class="fonw-800 color-#646cff">{record.moduleNo}</span>;
    }
  },
  {
    key: 'custProdNo',
    dataIndex: 'custProdNo',
    title: '客户型号',
    align: 'center',
    checked: true,
    ellipsis: true
  },
  {
    key: 'peType',
    dataIndex: 'peType',
    title: '类型',
    align: 'center',
    checked: true,
    ellipsis: true,
    width: 100
  },
  {
    key: 'custAB',
    dataIndex: 'custAB',
    title: '客户名称',
    align: 'center',
    checked: true,
    ellipsis: true,
    width: 160
  }
];

const selectRow = ref(null);

function handleSelectChange(row) {
  selectRow.value = row[0];
}

function getSelectRow() {
  return selectRow.value;
}

function search() {
  tableRef.value.getData();
}

function reset() {
  resetSearchParams();
  search();
}

defineExpose({
  getSelectRow
});
</script>

<template>
  <div class="h-full w-full flex-col-stretch gap-8px overflow-hidden lt-sm:overflow-auto">
    <CommonSearch
      v-model:searchParams="searchParams"
      :form-list="formList"
      @search="search"
      @reset="reset"
    ></CommonSearch>
    <Table
      ref="tableRef"
      v-model:searchParams="searchParams"
      :column="column"
      :show-row-selection="true"
      row-key="ECNno"
      :scroll="{ y: 'auto' }"
      :is-init-get-data="false"
      url="/erpsyncmes/Mi/findModuleNo"
      :auto-generate-uuid="true"
      class="h-full"
      row-selection-type="radio"
      @table-select-change="handleSelectChange"
    ></Table>
  </div>
</template>

<style lang="scss" scoped></style>
